package GUI;

import java.awt.FlowLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.SimpleDateFormat;
import java.util.Date;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.Timer;

public class DigitalClock extends JLabel {
 private String pattern;
 private Timer timer;
 private int delay;

 public DigitalClock(String pattern){
  this.pattern = pattern;
  this.delay = 1000;
  createTimer();
  timer.start();
 }
 

 public DigitalClock(String pattern, int delay){
  this.pattern = pattern;
  this.delay = delay;
  createTimer();
  timer.start();
 }


 public DigitalClock(){
  pattern = "HH:mm:ss" ;
  this.delay = 1000;
  createTimer();
  timer.start();
 }

 private void createTimer(){
  timer = new Timer(delay, new ActionListener() {
   public void actionPerformed(ActionEvent arg0) {
    setText(new SimpleDateFormat(pattern).format(new Date()));
   }
  });
 }
 
 public String getPattern() {
  return pattern;
 }
 
 public void setPattern(String pattern) {
  this.pattern = pattern;
 }
 
 public Timer getTimer() {
  return timer;
 }
 
 public int getDelay() {
  return delay;
 }
 
 public void setDelay(int delay) {
  this.delay = delay;
 }
 

}